<?php
namespace app\admin\controller;
use app\admin\model\Base;
use think\Controller;
use think\Db;
use think\Model;
class Chart extends Common{
    public function _initialize(){
        parent::_initialize();
    }
    //跳统计管理页面-------
    public function show(){
       //用户性别统计
        $rs = Db::query("select (sum(sex=0)/count(sex)) as nan,(sum(sex=1))/count(sex) as nv from userinfo");
        $nan = intval($rs[0]['nan']*100);
        $nv = ceil($rs[0]['nv']*100);
        //var_dump($nan.'###'.$nv);die;
        $this->assign("nan",$nan);
        $this->assign("nv",$nv);
        //用户消费统计
        $time = time();
        $time = date('Y-m-d', $time);
        $time = explode('-',$time);
        $time = $time['0'];
        $rss = Db::query("SELECT sum(money) as money FROM `order` WHERE `year`=$time  group by `month`");
        foreach ( $rss as $money ) {
            $val[] = $money['money'];
        }
        $this->assign("rss",$val);
        return $this->fetch('show');
    }

    public function select(){
        $times = isset($_POST['times'])?$_POST['times']:"";
        $time = explode('-',$times);
        $timey = $time['0'];
        $timem = $time['1'];
        if($timem<10){
            $timem = str_replace ("0", "", $timem);
            $timem = intval ($timem);
        }
        $rss = Db::query("SELECT sum(money) as money FROM `order` WHERE `year`=$timey&&`month`<=$timem  group by `month`");
        foreach ( $rss as $money ) {
            $val[] = $money['money'];
        }
        $this->assign("rss",$val);
        return $val;
    }

}